import * as path from "path";
import { spawn } from "child_process";

export async function BuildTSBuffer(filePath: string, outPath: string) {
    const folderPath = path.dirname(filePath);
    const fileName = path.basename(filePath);
    const cmdContent = `cd ${folderPath} & tsbuffer proto -i ${fileName} -o ${outPath}`;

    // console.log(filePath);
    // console.log(folderPath);
    // console.log(cmdContent);

    const child = spawn("cmd.exe", ["/c", cmdContent]);
    child.stdout.on('data', (data) => {
        console.log(data.toString());
    });

    child.stderr.on('data', (data) => {
        console.error(data.toString());
    });

    child.on('close', (code) => {
        console.log(`子进程退出码：${code}`);
    });
}